package com.yinhe.music.yhmusic.enums;

import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.utils.Preferences;
import com.yinhe.music.yhmusic.utils.ToastUtils;

/**
 * 播放模式
 * Created by wcy on 2015/12/26.
 */
public enum PlayModeEnum {
    LOOP(0),
    SHUFFLE(1),
    ONE(2);

    private int value;

    PlayModeEnum(int value) {
        this.value = value;
    }

    public static PlayModeEnum valueOf(int value) {
        switch (value) {
            case 0:
                return LOOP;
            case 1:
                return SHUFFLE;
            case 2:
                return ONE;
            default:
                return LOOP;
        }
    }

    public static PlayModeEnum switchPlayMode() {
        PlayModeEnum mode = PlayModeEnum.valueOf(Preferences.getPlayMode());
        switch (mode) {
            case LOOP:
                mode = PlayModeEnum.SHUFFLE;
                ToastUtils.show(R.string.mode_shuffle);
                break;
            case SHUFFLE:
                mode = PlayModeEnum.ONE;
                ToastUtils.show(R.string.mode_one);
                break;
            case ONE:
                mode = PlayModeEnum.LOOP;
                ToastUtils.show(R.string.mode_loop);
                break;
        }
        Preferences.savePlayMode(mode.value());
        return mode;
    }

    public static PlayModeEnum setMode(PlayModeEnum mode) {
        switch (mode) {
            case LOOP:
                mode = PlayModeEnum.LOOP;
                ToastUtils.show(R.string.mode_loop);
                break;
            case SHUFFLE:
                mode = PlayModeEnum.SHUFFLE;
                break;
            case ONE:
                mode = PlayModeEnum.ONE;
                ToastUtils.show(R.string.mode_shuffle);
                break;
        }
        Preferences.savePlayMode(mode.value());
        return mode;
    }

    public int value() {
        return value;
    }
}
